{% extends 'base.html' %}
{% block css %}
<link href="/static/css/dataTables.bootstrap.min.css" rel="stylesheet">
{% endblock %}
{% block content %}
<div class="right_col" role="main">
    <div class="">
        <div class="clearfix"></div>

        <div class="row">
            <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
                    <div class="x_title">
                        <h2>Salt主机列表 </h2>

                        <div class="clearfix"></div>
                    </div>
                    <button type="button" class="btn btn-success" title="刷新所有资产" onclick="generate(this);">刷新所有</button>
                    <div class="x_content">
                        <div class="ln_solid"></div>
                            <a class="btn btn-default" href="#" role="button">新增</a>
                            <a class="btn btn-default" href="#" role="button">修改</a>
                        </div>
                        	<table id="datatable1" class="table table-striped table-bordered">
                            <thead>
                                <tr>
                                    <td>多选</td>
                                    <th>序列号</th>
                                    <th>SN</th>
                                    <th>ip地址</th>
                                    <th>操作系统</th>
                                    <th>cpu核数</th>
                                    <th>内存信息</th>
                                    <th>主机名</th>
                                    <th>操作</th>

                                </tr>
                            </thead>
                            <tbody>
                                    {% for host_ip in host_list %}
                                <tr>
                                    <td><input class="icheck" type="checkbox" value="1" name="id"></td>
                                    <td>{{ forloop.counter }}</td>
                                    <td>{{ host_ip.sn }}</td>
                                    <td>{{ host_ip.ip }}</td>
                                    <td>{{ host_ip.kernel }}</td>
                                    <td>{{ host_ip.num_cpus }}</td>
                                    <td>{{ host_ip.mem_total }}</td>
                                    <td>{{ host_ip.hostname }}</td>
                                    <td style="padding-left:5px;">
                                        <a  target="_blank" name="connect-host"  host_id="{{ host_ip.sn }}" style="text-decoration:none;" data-toggle="tooltip" data-placement="right" title="webssh"><span class="fa fa-desktop"></span> </a>
                                     </td>

                                </tr>
                                {% endfor %}
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}
{% block js %}
<script src="/static/js/jquery.dataTables.min.js"></script>
<script src="/static/js/dataTables.bootstrap.min.js"></script>
<script>
function generate(doc) {
$.ajax({
    url:'/op/update_host_info',
    type:'GET',
    success:function (arg) {
        if (arg)
            alert('更新成功')
    },
    error:function () {
       alert('更新失败')
    }
});
};

//连接服务器

 $(document).ready(function(){
            $("td a[name='connect-host']").click(function () {
                var host_id = $(this).attr('host_id');
                params = {
                    "host_id":host_id,
                }
                 $.ajax({
                    type: "POST",
                    url: "/op/connecthost",
                    data: params,
                    success: function (res) {
//                        alert(res)
//                        if (res == 0) {
//                         window.location.href = "/op/index";

//                        }
                },
            });

        });
    });
</script>

{% endblock %}
